package com.gking.centerSystem.controller.otherApi;


import com.gking.centerSystem.AOP.DesensitizeDataAspectService;
import com.gking.centerSystem.common.Result;
import com.gking.centerSystem.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Slf4j
@RestController
@RequestMapping("/other/desensitizeData")
public class DesensitizeDataController {


    @Resource
    private DesensitizeDataAspectService desensitizeDataAspectService;

    /**
     * 脱敏校验认证
     *
     * @param user 密码
     * @return 到期时间戳
     */
    @PostMapping("/verify")
    public Result<Long> verify(@RequestBody User user) {
        try {
            long dataVerifyExpireTime = desensitizeDataAspectService.verify(user.getPassword());
            if (dataVerifyExpireTime == 0L) return Result.error("校验失败，请重新校验");
            return Result.success("校验成功，有效期有限，失效后请重新校验", dataVerifyExpireTime);
        } catch (Exception e) {
            log.error("脱敏校验认证失败", e);
            return Result.error(e.getMessage());
        }
    }

    /**
     * 获取脱敏校验认证状态
     *
     * @return Boolean
     */
    @GetMapping("/verifyStatus")
    public Result<Boolean> verifyStatus() {
        try {
            boolean dataVerifyStatus = desensitizeDataAspectService.getDataVerifyStatus();
            return Result.success("获取脱敏校验状态成功", dataVerifyStatus);
        } catch (Exception e) {
            log.error("获取脱敏校验状态失败", e);
            return Result.error(e.getMessage());
        }
    }


    /**
     * 获取脱敏校验认证过期时间
     *
     * @return 到期时间戳
     */
    @GetMapping("/getExpireTime")
    public Result<Long> getDataVerifyExpireTime() {
        try {
            long dataVerifyExpireTime = desensitizeDataAspectService.getDataVerifyExpireTime();
            return Result.success("获取脱敏到期时间戳成功", dataVerifyExpireTime);
        } catch (Exception e) {
            log.error("获取脱敏到期时间戳失败", e);
            return Result.error(e.getMessage());
        }
    }


}
